package com.mlf.observer.demo01;

import lombok.Data;

import java.util.Observable;
import java.util.Observer;

/**
 * 观察者二号 - 温度报警
 */
@Data
public class TemperatureAlarm implements Observer {
    private static final double MAX_TEMP = 30.0;
    private static final double MIN_TEMP = 10.0;

    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof TemperatureSensor) {
            double temperature = (Double) arg;
            if (temperature > MAX_TEMP) {
                System.out.println("温度过高，请及时处理！(" + temperature + "°C)");
            }else if (temperature < MIN_TEMP) {
                System.out.println("温度过低，请及时处理！(" + temperature + "°C)");
            }
        }
    }
}
